import numpy as np

array = np.random.randint(low=1, high=1000, size=10)

print(array)

# 先排序，在查找
array.sort()
print(array)


def block_search(a: list, target: int) -> object:
    return search(0, len(a) - 1, a, target)


def search(low: int, high: int, a: list, target: int) -> object:
    if low <= high:
        middle = low + (target - a[low]) // (a[high] - a[low]) * (high - low) if a[high] != a[low] else low
        if a[middle] == target:
            return middle + 1
        elif a[middle] > target:
            return search(low, middle - 1, a, target)
        elif a[middle] < target:
            return search(middle + 1, high, a, target)
    return -1


value = array[np.random.randint(low=0, high=9, size=1)]

print(value)

print(block_search(array, value))
